VERSION 5.00
Begin VB.Form frmSystray 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "CDOrganizer Systray"
   ClientHeight    =   570
   ClientLeft      =   150
   ClientTop       =   720
   ClientWidth     =   1515
   Icon            =   "frmSystray.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   570
   ScaleWidth      =   1515
   StartUpPosition =   3  'Windows Default
   Begin VB.PictureBox PicSystray 
      Height          =   495
      Left            =   0
      ScaleHeight     =   435
      ScaleWidth      =   1395
      TabIndex        =   0
      Top             =   0
      Width           =   1455
   End
   Begin VB.Menu MnuLista 
      Caption         =   "&Lista"
      Begin VB.Menu mnuOpenCD 
         Caption         =   "Apri CD-ROM"
      End
      Begin VB.Menu mnuCloseCD 
         Caption         =   "Chiudi CD-ROM"
      End
      Begin VB.Menu mnuRipristina 
         Caption         =   "&Principale"
      End
      Begin VB.Menu mnuAbout 
         Caption         =   "A&bout"
      End
      Begin VB.Menu mnuEsci 
         Caption         =   "&Esci"
      End
   End
End
Attribute VB_Name = "frmSystray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'tipo necessario per inserire nella systray
Private Type NOTIFYICONDATA
    cbSize As Long
    hwnd As Long
    uId As Long
    uFlags As Long
    ucallbackMessage As Long
    hIcon As Long
    szTip As String * 64
End Type

Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_RBUTTONUP = &H205
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

Dim t As NOTIFYICONDATA
Dim TIPS As String

Private MenuBitmap() As Variant
Private Const NUM_ICON As Integer = 5
Private Sub Form_Load()
    Dim i As Integer
    
    Call ModLanguage.MLSLoadLanguage(Me)
    
    t.cbSize = Len(t)
    t.hwnd = PicSystray.hwnd
    t.uId = 1&
    t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    t.ucallbackMessage = WM_MOUSEMOVE
    t.hIcon = Me.Icon
    t.szTip = TIPS & Chr$(0)
    Shell_NotifyIcon NIM_ADD, t
    Me.Hide
    
    'nasconde tutti i form al momento visibili
    For i = Forms.Count - 1 To 0 Step -1
        If Forms(i).Caption <> Me.Caption Then
            Forms(i).Hide
        End If
    Next i
    
    #If USE_CUSTOM_MENU = 1 Then
        Call FillIcon
        ModODMenus.SetFont = Me.Font
        ModODMenus.SetBmp = MenuBitmap
        ModODMenus.startODMenus Me, True
    #End If
    
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    On Error Resume Next
    t.cbSize = Len(t)
    t.hwnd = PicSystray.hwnd
    t.uId = 1&
    Shell_NotifyIcon NIM_DELETE, t
    
    #If USE_CUSTOM_MENU = 1 Then
        ModODMenus.stopODMenus Me
        Erase MenuBitmap
    #End If
End Sub

Private Sub mnuCloseCD_Click()
    ModSetFirstCd.OpenCloseCDROM (False)
End Sub
Private Sub mnuOpenCD_Click()
    ModSetFirstCd.OpenCloseCDROM (True)
End Sub

'quando premi e muoi sopra la systray
Private Sub PicSystray_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    On Error Resume Next
    Static rec As Boolean, msg As Long
    msg = x / Screen.TwipsPerPixelX
    If rec = False Then
        rec = True
        Select Case msg
            Case WM_RBUTTONUP:
                Me.PopupMenu MnuLista
        End Select
        rec = False
    End If
End Sub

Private Sub mnuEsci_Click()
    On Error Resume Next
    Dim i As Integer
    While Forms.Count > 1
        i = 0
        While Forms(i).Caption = Me.Caption
            i = i + 1
        Wend
        Unload Forms(i)
    Wend
    Unload Me
End Sub

Private Sub MnuRipristina_Click()
    On Error Resume Next
    frmMain.Show
    frmMain.SetFocus
    Unload Me
End Sub

Private Sub mnuAbout_Click()
    frmAbout.Show vbModal, Me
End Sub

 Private Sub FillIcon()
 
    ReDim MenuBitmap(NUM_ICON, 2)
    
    MenuBitmap(6, 0) = 117
    MenuBitmap(6, 1) = 118
    MenuBitmap(6, 2) = mnuRipristina.Caption '"&Systray"
    
    MenuBitmap(7, 0) = 123
    MenuBitmap(7, 1) = 124
    MenuBitmap(7, 2) = mnuAbout.Caption '"Abo&ut"
    
    MenuBitmap(8, 0) = 121
    MenuBitmap(8, 1) = 122
    MenuBitmap(8, 2) = mnuEsci.Caption '"&Esci"
    
    MenuBitmap(9, 0) = 155
    MenuBitmap(9, 1) = 154
    MenuBitmap(9, 2) = mnuCloseCD.Caption
    
    MenuBitmap(10, 0) = 157
    MenuBitmap(10, 1) = 156
    MenuBitmap(10, 2) = mnuOpenCD.Caption
End Sub

